///**
// * Copyright (C) 2012 The SkyTvOS Project
// * <p>
// * Version     Date           Author
// * ─────────────────────────────────────
// * 2015-5-13         yellowlgx
// */
//
//package com.skyworth.ui.api;
//
//import android.content.Context;
//import android.os.Handler;
//import android.os.Looper;
//import android.os.Message;
//import android.util.AttributeSet;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.FrameLayout;
//import android.widget.LinearLayout;
//
//import com.skyworth.commen.ui.R;
//import com.skyworth.util.SkyScreenParams;
//
///**
// * @author yellowlgx
// * @version TODO (write something)
// * @ClassName SkyWithBGLoadingView * @Description
// * <p>
// * 带背景的loadingView，也就是普通的View，直接创建就能使用，大小由使用者控制，其中显示时调用showLoading()，消失调用
// * dismissLoading()即可；
// * </p>
// * @date 2015-5-13
// */
//public class SkyWithBGLoadingView extends FrameLayout {
//    private LinearLayout bgLayout;
//    private SkyLoadingView loadingView;
//    private FrameLayout.LayoutParams mLoadP;
//
//    public SkyWithBGLoadingView(Context context) {
//        this(context, null);
//    }
//
//    public SkyWithBGLoadingView(Context context, AttributeSet attrs) {
//        this(context, attrs, 0);
//    }
//
//    public SkyWithBGLoadingView(Context context, AttributeSet attrs, int defStyle) {
//        super(context, attrs, defStyle);
//        bgLayout = new LinearLayout(context);
//        bgLayout.setGravity(Gravity.CENTER);
//        mLoadP = new FrameLayout.LayoutParams(SkyScreenParams.getInstence(context)
//                .getResolutionValue(180), SkyScreenParams.getInstence(context).getResolutionValue(
//                180), Gravity.CENTER);
//        this.addView(bgLayout, mLoadP);
//        bgLayout.setBackgroundResource(R.drawable.ui_sdk_loading_bg);
//        loadingView = new SkyLoadingView(context);
//        loadingView.setStrokeWidth(SkyScreenParams.getInstence(context).getResolutionValue(5));
//        bgLayout.addView(loadingView,
//                new LinearLayout.LayoutParams(SkyScreenParams.getInstence(context)
//                        .getResolutionValue(70), SkyScreenParams.getInstence(context)
//                        .getResolutionValue(70)));
//        super.setVisibility(View.INVISIBLE);
//    }
//
//    public void setScaleW_H(int w, int h) {
//        LinearLayout.LayoutParams loadP = (LinearLayout.LayoutParams) loadingView.getLayoutParams();
//        loadP.width = (int) ((float) (w * loadP.width) / mLoadP.width + 0.5f);
//        loadP.height = (int) ((float) (h * loadP.height) / mLoadP.height + 0.5f);
//        loadingView.setLayoutParams(loadP);
//
//        int strokeW = (int) ((float) (w * loadingView.getStokeWidth()) / mLoadP.width + 0.5f);
//        loadingView.setStrokeWidth(strokeW);
//
//        mLoadP.width = (int) ((float) (w * mLoadP.width) / mLoadP.width + 0.5f);
//        mLoadP.height = (int) ((float) (h * mLoadP.height) / mLoadP.height + 0.5f);
//        bgLayout.setLayoutParams(mLoadP);
//
//        ViewGroup.LayoutParams thisP = this.getLayoutParams();
//        thisP.width = w;
//        thisP.height = h;
//        this.setLayoutParams(thisP);
//    }
//
//    public int getLoadingViewWidth() {
//        return mLoadP.width;
//    }
//
//    public int getLoadingViewHeight() {
//        return mLoadP.height;
//    }
//
//    private static final int MSG_LOADING_SHOW = 1;
//    private static final int MSG_LOADING_HIDE = 2;
//    private final Handler handler = new Handler(Looper.getMainLooper()) {
//        @Override
//        public void handleMessage(Message msg) {
//            Log.d("LOADING", "handleMessage:" + msg.what);
//            switch (msg.what) {
//                case MSG_LOADING_SHOW: {
//                    SkyWithBGLoadingView.super.setVisibility(View.VISIBLE);
//                    loadingView.startAnim();
//                    break;
//                }
//                case MSG_LOADING_HIDE: {
//                    loadingView.stopAnim();
//                    SkyWithBGLoadingView.super.setVisibility(View.GONE);
//                    break;
//                }
//            }
//        }
//    };
//
//    @Override
//    public void setVisibility(int visibility) {
//        //乱调  setVisibility
////        StackTraceElement[] elements = Thread.currentThread().getStackTrace();
////        for (StackTraceElement element : elements) {
////            Log.e("LOADING", element.toString());
////        }
//        Log.e("LOADING", "stupid call setVisibility " + visibility);
//    }
//
//    public void showLoading(long delay) {
//        Log.d("LOADING", "call showLoading delay:" + delay);
//        synchronized (handler) {
//            if (handler.hasMessages(MSG_LOADING_HIDE)) {
//                Log.d("LOADING", "call showLoading hasHide continue show!");
//                handler.removeMessages(MSG_LOADING_HIDE);
//            } else {
//                boolean bSpinning = isSpinning();
//                boolean hasShow = handler.hasMessages(MSG_LOADING_SHOW);
//                Log.d("LOADING", "call showLoading bSpinning:" + bSpinning + "  hasShow:" + hasShow);
//                if (!hasShow)
//                    handler.sendEmptyMessageDelayed(MSG_LOADING_SHOW, delay);
//            }
//        }
//    }
//
//    public void showLoadingWithDelay() {
//        showLoading(1500);
//    }
//
//    public void showLoading() {
//        showLoading(0);
////        SkyWithBGLoadingView.this.setVisibility(View.VISIBLE);
////        loadingView.startAnim();
//    }
//
//    // 设置圆圈宽度
//    public void setStrokeWidth(int width) {
//        loadingView.setStrokeWidth(width);
//    }
//
//    public void dismissLoading() {
//        Log.d("LOADING", "call dismissLoading");
//        synchronized (handler) {
//            handler.removeMessages(MSG_LOADING_SHOW);
//            boolean hasHide = handler.hasMessages(MSG_LOADING_HIDE);
//            Log.d("LOADING", "call dismissLoading hasHide:" + hasHide);
//            if (!hasHide)
//                handler.sendEmptyMessageDelayed(MSG_LOADING_HIDE, 200);
//        }
////        loadingView.stopAnim();
////        SkyWithBGLoadingView.this.setVisibility(View.GONE);
//    }
//
//    public boolean isSpinning() {
//        return loadingView.isSpinning();
//    }
//
//}
